package com.edgar.plugin.hooks;

import android.os.RemoteException;
import android.util.Log;

import java.lang.reflect.Method;

/**
 * Created by Edgar on 2018/2/8.
 */
public class HookMethodHandle {

    private static final String TAG = "HookMethodHandle";

    Object onInvoke(Object receiver, Method method,Object[] args)throws Throwable{
        boolean isReplace = onReplaceParameter(args);
        if (isReplace){
            Log.d(TAG,"Replace method parameter:"+method.getName());
        }
        Object result = method.invoke(receiver,args);
        onInvokeFinish(receiver,method,args,isReplace);
        return result;
    }

    protected boolean onReplaceParameter(Object[] args)throws RemoteException{
        return false;
    }

    protected void onInvokeFinish(Object receiver, Method method,Object[] args,boolean isReplace){}
}